#include<iostream>
#include<unistd.h>
 #include <sys/types.h>
#include <sys/stat.h>
 #include <sys/types.h>
#include <fcntl.h>
#include<string.h>

int main()
{
    const char *filename="./testFifo";
    int ret1=access(filename,F_OK);
    if(ret1==-1)
    {
    int ret=mkfifo(filename,0644);
    if(ret==-1)
    {
        perror("mkfifo error:");
        _exit(-1);
    }
    }
    int readFd=open(filename,O_RDONLY);
    if(readFd==-1)
    {
        perror("open fifo error:");
        _exit(-1);
    }
       char buf[128]={0};
       int readBytes=0;
       while(1)
       {
        readBytes=read(readFd,buf,sizeof(buf));
         if(readBytes==0)
        {
            break;
        }
        if(readBytes<0)
        {
            perror("read error:");
            _exit(-1);
        }
        buf[readBytes]='\0';
        printf("readBytes=%d,\tbuf=%s\n",readBytes,buf);ap
        memset(buf,0,sizeof(buf));
       }

/*关闭文件*/
    close(readFd);
}
